package userHelp

import (
	myredis "common/redis"
	"encoding/json"
	"time"
)

type MemberTransaction struct {
	BillNo       string  `db:"bill_no" json:"bill_no" cbor:"bill_no"`                   //转账|充值|提现ID
	UID          string  `db:"uid" json:"uid" cbor:"uid"`                               //用户ID
	CashType     int     `db:"cash_type" json:"cash_type" cbor:"cash_type"`             //0:转入1:转出2:转入失败补回3:转出失败扣除4:存款5:提现
	Amount       float64 `db:"amount" json:"amount" cbor:"amount"`                      //用户填写的转换金额
	BeforeAmount float64 `db:"before_amount" json:"before_amount" cbor:"before_amount"` //账变前的金额
	AfterAmount  float64 `db:"after_amount" json:"after_amount" cbor:"after_amount"`    //账变后的金额
	CreatedAt    int64   `db:"created_at" json:"created_at" cbor:"created_at"`          //
	PlatformID   string  `db:"platform_id" json:"platform_id" cbor:"platform_id"`       //场馆id
	GameTax      float64 `db:"game_tax" json:"game_tax" cbor:"game_tax"`                //1正式 2测试 3代理
	GameId       string  `db:"game_id" json:"game_id" cbor:"game_id"`                   //游戏id
	RouteName    string  `db:"route_name" json:"route_name" cbor:"route_name"`          //线路名称
	Sandbag      int     `db:"sandbag" json:"sandbag" cbor:"sandbag"`                   //标识此游戏记录是否放水原因生成
}

func AddBalanceTransactionRecord(Uid string, ChangeMount float64, CashType int, PlatformID string,
	BillNo string, gameTax float64, gameId string, routeName string, sandbag int) {
	balance := GetBalanceFloat64ByUid(Uid)
	betAfterAmount := balance + ChangeMount
	trans := MemberTransaction{
		UID:          Uid,
		PlatformID:   PlatformID,
		BillNo:       BillNo,
		CashType:     CashType,
		Amount:       ChangeMount,
		BeforeAmount: balance,
		AfterAmount:  betAfterAmount,
		GameTax:      gameTax,
		CreatedAt:    time.Now().UnixMilli(),
		GameId:       gameId,
		Sandbag:      sandbag,
		RouteName:    routeName,
	}

	//query, _, _ := dialect.Insert("tbl_balance_transaction").Rows(trans).ToSQL()
	data, _ := json.Marshal(trans)
	myredis.UpdateTransactionToRedis(data)
	//myredis.UpdateTransactionToRedis(trans)
}
